#include <iostream>
#include <vector>
#include <string>

using namespace std;

class Solution {
public:
    static int lengthOfLongestSubstring(string s) {
        int left = 0, right = 0, ret = 0;
        vector<int> hash(1000);
        //这道题的字符包括了整张ASCII表，所以hash的大小要给的多一些
        for(;right < s.size(); right++)
        {
            hash[s[right]] += 1;//进窗口
            while(hash[s[right]] == 2)/*判断*/ 
                hash[s[left++]] -= 1;//出窗口
            ret = max(ret, right-left+1);
        }
        return ret;
    }
};

int main()
{
    // string s = "abcabcbb";
    // string s = "bbbbb";
    // string s = "pwwkew";
    string s = "ibaz";
    cout << Solution::lengthOfLongestSubstring(s) << endl;
    return 0;
}